<!--
  -    Copyright (c) 2018-2025, hycloud All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without
  - modification, are permitted provided that the following conditions are met:
  -
  - Redistributions of source code must retain the above copyright notice,
  - this list of conditions and the following disclaimer.
  - Redistributions in binary form must reproduce the above copyright
  - notice, this list of conditions and the following disclaimer in the
  - documentation and/or other materials provided with the distribution.
  - Neither the name of the pig4cloud.com developer nor the names of its
  - contributors may be used to endorse or promote products derived from
  - this software without specific prior written permission.
  - Author: hycloud
  -->
<template>
    <div class="execution">
        <basic-container>
            <avue-crud ref="crud"
                       :page.sync="page"
                       :data="tableData"
                       :permission="permissionList"
                       :table-loading="tableLoading"
                       :option="tableOption"
                       @on-load="getList"
                       @search-change="searchChange"
                       @refresh-change="refreshChange"
                       @size-change="sizeChange"
                       @current-change="currentChange">
                       <template slot-scope="{ row }" slot="menu">
                            <el-button
                            icon="el-icon-position"
                            type="text"
                            @click="deviceshow(row)"
                            >查看记录</el-button
                            >
                        </template>
            </avue-crud>
        </basic-container>
        <el-dialog title="查看" v-if="modal4" :visible.sync="modal4" width="60%" append-to-body>
        <div v-loading="loading">
          <div class="form">
            <el-form ref="form" label-width="100px" label-position="left">
              <el-row :gutter="20">
                <el-col :span="12">
                  <el-form-item label="计划:">
                    <span>{{
                      recordDetail ? recordDetail.planName : ""
                    }}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="计划日期:">
                    <span>{{ recordDetail ? recordDetail.planDate : "" }}</span>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="12">
                  <el-form-item label="养护时间:">
                    <span>{{
                      recordDetail ? recordDetail.createTime : ""
                    }}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="养护单位:">
                    <span>{{
                      recordDetail ? getUnitName(recordDetail.unitId) : ""
                    }}</span>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="12">
                  <el-form-item label="养护人:">
                    <span>{{
                      recordDetail ? recordDetail.handleRealname : ""
                    }}</span>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="备注:">
                    <span>{{ recordDetail ? recordDetail.content : "" }}</span>
                  </el-form-item>
                </el-col>
              </el-row>
              <!-- <el-row>
                <el-col :span="24">
                  <el-form-item label="文件列表:">
                    <div
                      v-if="
                        recordDetail &&
                        JSON.parse(recordDetail.imageMultiple) instanceof Array
                      "
                    >
                      <el-link
                        v-for="(item, index) in JSON.parse(
                          recordDetail.imageMultiple
                        )"
                        :key="index"
                        :underline="false"
                        type="primary"
                        class="fileList"
                        @click="filedownload(item.url, item.originName)"
                        >{{ item.originName }}</el-link
                      >
                    </div>
                  </el-form-item>
                </el-col>
              </el-row> -->

              <el-row>
                <el-col :span="24">
                  <avue-crud
                    :option="fyoperationOption"
                    :data="fyoperationData"
                  >
                    <template slot-scope="scope" slot="menuLeft"> 养护费用： </template>
                  </avue-crud>
                  <div class="divs">
                  <table class style="width:100%;">
                    <tbody class>
                      <tr>
                        <td colspan="1" rowspan="1" class style="width:15.7%">
                          <div class="cell"></div>
                        </td>
                        <td colspan="1" rowspan="1" class style="width:10.9%">
                          <div class="cell"></div>
                        </td>
                        <td colspan="1" rowspan="1" class style="width:10.9%">
                          <div class="cell">合计:{{fytotal}}</div>
                        </td>
                      </tr>
                    </tbody>
                  </table>
                </div>
                </el-col>
              </el-row>
            </el-form>
          </div>
        </div>
      </el-dialog>
    </div>
</template>

<script>
    import {fetchList, getObj, addObj, putObj, delObj} from '@/api/maintenance/maintenancerecord'
    import {fetchList as fetchList2} from '@/api/maintenance/maintenanceunit'
    import {fyoperationOption} from '@/const/crud/maintenance/maintenanceplanasset'
    import {tableOption} from '@/const/crud/maintenance/maintenancerecord'
    import {mapGetters} from 'vuex'

    export default {
        name: 'maintenancerecord',
        data() {
            return {
                modal4: false,
                loading: false,
                recordDetail: {},
                fyoperationOption:fyoperationOption,
                fyoperationData:[],
                fytotal:0,
                searchForm: {},
                tableData: [],
                unitList: [],
                page: {
                    total: 0, // 总页数
                    currentPage: 1, // 当前页数
                    pageSize: 20 // 每页显示多少条
                },
                tableLoading: false,
                tableOption: tableOption
            }
        },
        computed: {
            ...mapGetters(['permissions']),
            permissionList() {
                return {
                    addBtn: false,
                    delBtn: false,
                    editBtn: false
                };
            }
        },
        created() {
            this.init()
        },
        methods: {
            init() {
                fetchList2({size: -1}).then(response => {
                    this.unitList = response.data.data.records
                })
            },
            getUnitName(id) {
                let list = this.unitList.filter(item => {
                    return item.unitId === id
                })[0]
                return list.name
            },
            getList(page, params) {
                this.tableLoading = true
                fetchList(Object.assign({
                    current: page.currentPage,
                    size: page.pageSize
                }, params, this.searchForm )).then(response => {
                    this.tableData = response.data.data.records
                    this.page.total = response.data.data.total
                    this.tableLoading = false
                }).catch(() => {
                    this.tableLoading=false
                })
            },
            deviceshow(row) {
                this.recordDetail = {};
                this.loading = true;
                getObj(row.recordId).then((res) => {
                    this.recordDetail = res.data.data;
                    this.modal4 = true
                    this.loading = false
                    this.fyoperationData = res.data.data.recordItemList
                    this.fytotal = res.data.data.totalPrice
                }).catch(() => {
                    this.loading = false;
                });
            },
            sizeChange(pageSize){
                this.page.pageSize = pageSize
            },
            currentChange(current){
                this.page.currentPage = current
            },
            searchChange(form, done) {
                this.searchForm = form
                this.page.currentPage = 1
                this.getList(this.page, form)
                done()
            },
            refreshChange() {
                this.getList(this.page)
            }
        }
    }
</script>